import { request } from '../../utils/request'
import type { OperationLog, ApiResponse } from '../../types/app.d'

/**
 * 获取操作日志列表
 */
export const getOperationLogList = (params: {
  page: number
  pageSize: number
  username?: string
  operation?: string
  status?: number
  beginTime?: string
  endTime?: string
  ip?: string
}) => {
  return request.get<ApiResponse<{
    list: OperationLog[]
    total: number
  }>>('/system/log/operation/list', { params })
}

/**
 * 获取操作日志详情
 */
export const getOperationLogInfo = (id: string) => {
  return request.get<ApiResponse<OperationLog>>(`/system/log/operation/${id}`)
}

/**
 * 删除操作日志
 */
export const deleteOperationLog = (id: string) => {
  return request.delete<ApiResponse>(`/system/log/operation/${id}`)
}

/**
 * 批量删除操作日志
 */
export const batchDeleteOperationLog = (ids: string[]) => {
  return request.delete<ApiResponse>('/system/log/operation/batch', { data: { ids } })
}

/**
 * 清空操作日志
 */
export const cleanOperationLog = () => {
  return request.delete<ApiResponse>('/system/log/operation/clean')
}

/**
 * 导出操作日志
 */
export const exportOperationLog = (params?: {
  username?: string
  operation?: string
  status?: number
  beginTime?: string
  endTime?: string
  ip?: string
}) => {
  return request.get<ApiResponse<string>>('/system/log/operation/export', { params })
}